module SimplyRestfulBackport
  module FormTagHelper
    def self.included(base)
      base.class_eval do
        alias_method :form_tag_without_method, :form_tag
        alias_method :form_tag, :form_tag_with_method
      end
    end
    # Largely influenced by the Rails developers, revision 4607. All credit to them.
    def form_tag_with_method(url_for_options = {}, options = {}, *parameters_for_url, &proc)
      method_tag = ""
      case method = ((options.delete(:method) || url_for_options.delete(:method)).to_s rescue nil)
      when /^get$/i
        options[:method] = "get"
      when /^(delete|put)$/i
        options[:method] = "post"
        method_tag = tag(:input, :type => "hidden", :name => "_method", :value => method)
      else
        options[:method] = "post"
      end
      form_tag_without_method(url_for_options, options, *parameters_for_url, &proc) + method_tag
    end
  end
end